#ifndef _BASE_MUTEX_LOCKER_H_
#define _BASE_MUTEX_LOCKER_H_

#include "Base.Mutex.h"

#define LOCK_MUTEX(mutex) Maha::Base::MutexLocker _tmp_mutex_capt(&mutex)

namespace Maha
{
      namespace Base
      {
            class MutexLocker
            {
            public:

                  explicit MutexLocker(Maha::Base::Mutex *mutex)
                  {
                        this->mutex = mutex;
                        mutex->lock();
                  }
                  
                  explicit MutexLocker(Maha::Base::Mutex& mutex)
                  {
                        this->mutex = &mutex;
                        mutex.lock();
                  }
                  
                  ~MutexLocker()
                  {
                        mutex->unlock();
                  }
            
            private:
            
                  MutexLocker(const MutexLocker&);

                  MutexLocker& operator=(const MutexLocker&);

            private:
            
                  Maha::Base::Mutex *mutex;
            };
      }
}

#endif // _BASE_MUTEX_LOCKER_H_
